import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 实例化配置项
options = webdriver.ChromeOptions()
# 准备配置信息
user_data_dir = r'--user-data-dir=C:\Users\年轻人\AppData\Local\Google\Chrome\User Data'
# 添加配置项
options.add_argument(user_data_dir)
driver = webdriver.Chrome(options=options)
# 打开浏览器
driver.get("https://mail.163.com/")
driver.maximize_window()
# 定位写信按钮,点击进入写信页面
driver.find_element(By.ID, "_mail_component_149_149").click()
# 定位收件人输入框,并输入内容
driver.find_element(By.CLASS_NAME, "nui-editableAddr-ipt").send_keys("xiaoxiao_07140714@163.com")
# 定位主题输入框,并输入内容
driver.find_element(By.XPATH, "//input[@class='nui-ipt-input' and @maxlength='256']").send_keys('录取通知')
# 切换指定窗口
driver.switch_to.frame(driver.find_element(By.CLASS_NAME, "APP-editor-iframe"))
# 定位文本框,输入内容
driver.find_element(By.XPATH, '//html/body/p').send_keys('你好,肖大能,恭喜你,被大能每天笑哈哈集团录取')
# 返回主页面
driver.switch_to.default_content()
# 定位发送按钮,并点击发送
driver.find_element(By.XPATH, "//footer/div/span").click()

time.sleep(5)
driver.quit()
